package com.zf.shuashua.bean.advert;

import com.zf.shuashua.advert.AdvertConstants;
import com.zf.shuashua.api.Store;

import java.io.Serializable;
import java.util.List;

/**
 * 贴片广告配置
 */
public class PatchConfigBean implements Serializable {

    //提现弹窗
    private List<AdvertConfigBean> xdraw;
    //通用弹窗
    private List<AdvertConfigBean> common;
    //首页泡泡
    private List<AdvertConfigBean> bubble;
    //奖励弹窗
    private List<AdvertConfigBean> reword;

    private int indexCash = -1;
    private int indexCommon = -1;
    private int indexButtle = -1;
    private int indexReword = -1;

    /**
     * 轮动获取各个广告位对应的广告配置
     * @param advertType
     * @return
     */
    public AdvertConfigBean getConfigByType(String advertType){
        List<AdvertConfigBean> config = getConfigBean(advertType);
        if(config == null || config.size() < 1){
            return null;
        }
        if(config.size() == 1){
            return config.get(0);
        }
        int index = getIndexByType(advertType);
        return config.get(index);
    }

    private int getIndexByType(String advertType){
        int index = 0;
        switch (advertType) {
            case AdvertConstants.NATIVE_TYPE_COMMON:
                index = indexCommon + 1 < common.size() ? indexCommon + 1 : 0;
                indexCommon = index;
                Store.getInstance().setNativeCommonIndex(index);
                break;
            case AdvertConstants.NATIVE_TYPE_BUBBLE:
                index = indexButtle + 1 < bubble.size() ? indexButtle + 1 : 0;
                indexButtle = index;
                break;
            case AdvertConstants.NATIVE_TYPE_ENCOURAGE:
                index = indexReword + 1 < reword.size() ? indexReword + 1 : 0;
                indexReword = index;
                Store.getInstance().setNativeRewardIndex(index);
                break;
            case AdvertConstants.NATIVE_TYPE_WITHDRAW:
                index = indexCash + 1 < xdraw.size() ? indexCash + 1 : 0;
                indexCash = index;
//                Store.getInstance().setNativeCashIndex(index);
                break;
        }
        return index;
    }

    private List<AdvertConfigBean> getConfigBean(String advertType) {
        List<AdvertConfigBean> configBean = null;
        switch (advertType) {
            case AdvertConstants.NATIVE_TYPE_COMMON:
                configBean = common;
                break;
            case AdvertConstants.NATIVE_TYPE_BUBBLE:
                configBean = bubble;
                break;
            case AdvertConstants.NATIVE_TYPE_ENCOURAGE:
                configBean = reword;
                break;
            case AdvertConstants.NATIVE_TYPE_WITHDRAW:
                configBean = xdraw;
                break;
        }
        return configBean;
    }

    public List<AdvertConfigBean> getXdraw() {
        return xdraw;
    }

    public void setXdraw(List<AdvertConfigBean> xdraw) {
        this.xdraw = xdraw;
    }

    public List<AdvertConfigBean> getCommon() {
        return common;
    }

    public void setCommon(List<AdvertConfigBean> common) {
        this.common = common;
    }

    public List<AdvertConfigBean> getBubble() {
        return bubble;
    }

    public void setBubble(List<AdvertConfigBean> bubble) {
        this.bubble = bubble;
    }

    public List<AdvertConfigBean> getReword() {
        return reword;
    }

    public void setReword(List<AdvertConfigBean> reword) {
        this.reword = reword;
    }

    public int getIndexCash() {
        return indexCash;
    }

    public void setIndexCash(int indexCash) {
        this.indexCash = indexCash;
    }

    public int getIndexCommon() {
        return indexCommon;
    }

    public void setIndexCommon(int indexCommon) {
        this.indexCommon = indexCommon;
    }

    public int getIndexButtle() {
        return indexButtle;
    }

    public void setIndexButtle(int indexButtle) {
        this.indexButtle = indexButtle;
    }

    public int getIndexReword() {
        return indexReword;
    }

    public void setIndexReword(int indexReword) {
        this.indexReword = indexReword;
    }
}
